********************************
***Representativeness of Sample***
********************************

clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==1  {
cap cd "~\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/"
global draftout "../../Draft/Figures"
} 

use 3_clean_data, replace


*********************************
***Create Variables and Format***
*********************************

/*Order or Treatment Groups*
5 7 6 8 1 3 2 4 9 10
*/

replace dummy_source_obama=dummy_source_obama*100
replace dummy_source_trump=dummy_source_trump*100

gen prob_sourcecorrect=dummy_source_obama if (treat==2 | treat==4 | treat==6 | treat==8 | treat==10)
replace prob_sourcecorrect=dummy_source_trump if (treat==1 | treat==3 | treat==5 | treat==7 | treat==9)

gen prob_strength=prob_content_anti if treat>4 & treat<9
replace prob_strength=prob_content_pro if treat<5 & treat!=0

foreach y in 5 7 6 8 1 3 2 4 9 10 {
	gen t`y'=treatment==`y'
	}

global source5 	"Trump"
global source7 	"Actor, Trump"
global source6 	"Obama"
global source8 	"Actor, Obama"
global source1 	"Trump"
global source3 	"Actor, Trump"
global source2 	"Obama"
global source4 	"Actor, Obama"
global source9 	"Trump"
global source10 "Obama"
global message5 "Anti-Immigrant"
global message7 "Anti-Immigrant"
global message6 "Anti-Immigrant"
global message8 "Anti-Immigrant"
global message1 "Pro-Immigrant"
global message3 "Pro-Immigrant"
global message2 "Pro-Immigrant"
global message4 "Pro-Immigrant"
global message9 "Turkey"
global message10 "Turkey"
 
foreach y in 5 6 1 2 9 {
	global space`y' "[.2em]" 
	} 
foreach y in 8 4 10 {
	global space`y' "[1em]" 
	} 

*****************************
*****************************
*****************************

******************************************************************
****Density plots of Immigration Beliefs - Control Group****
******************************************************************

sum prob_index_anti if recruit==0 & treat==0
local repmean=round(r(mean)*10000)/10000
local repmean: di %6.3f `repmean'
sum prob_index_anti if recruit==1 & treat==0
local demmean=round(r(mean)*10000)/10000
local demmean: di %6.3f `demmean'

# delimit ;
twoway (kdensity prob_index_anti if recruit==0 & treat==0, lcolor(black) )
	(kdensity prob_index_anti if recruit==1 & treat==0, lcolor(black) lpattern(dash_dot) )
	,
	ylabel(, nogrid) 
	ytitle("Density" " ")
	xtitle(" " "Anti-Immigration Beliefs, {it:P(Anti)}" " ")
	legend(order(1 "Republicans" 2 "Democrats"))
	text(1.3 0.65 "Mean =`repmean'", color(black))
	text(1.3 0.15 "Mean =`demmean'", color(black))
	graphregion(color(white)) 
;# delimit cr

graph export "$draftout/2_Anti_ByParty_Control.eps", replace

*****************************************************
****Bar Graphs of Comparison to Gallup Immigration****
*****************************************************

gen n=_n if _n<4

gen space=.

gen sample_r=.
gen sample_d=.
gen party_r=.
gen party_d=.

gen imm_increase=pre_immlevel_raw5==1
gen imm_same=pre_immlevel_raw5==3
gen imm_decrease=pre_immlevel_raw5==5

sum imm_increase if recruit==0
replace sample_r=r(mean)*100 if n==1
sum imm_same if recruit==0
replace sample_r=r(mean)*100 if n==2
sum imm_decrease if recruit==0
replace sample_r=r(mean)*100 if n==3

sum imm_increase if recruit==1
replace sample_d=r(mean)*100 if n==1
sum imm_same if recruit==1
replace sample_d=r(mean)*100 if n==2
sum imm_decrease if recruit==1
replace sample_d=r(mean)*100 if n==3

*Manually Enter National Party Info
*Source: Gallup (2019)
*https://news.gallup.com/poll/259103/new-high-say-immigration-important-problem.aspx
replace party_r=0.13*100 if n==1
replace party_r=0.31*100 if n==2
replace party_r=0.54*100 if n==3

replace party_d=0.43*100 if n==1
replace party_d=0.42*100 if n==2
replace party_d=0.13*100 if n==3


label define gallup 1 `" "Immigration" "Should Increase" "' ///
	2 `" "Immigration" "No Change" "' ///
	3 `" "Immigration" "Should Decrease" "' , replace 

label values n gallup

*Sample vs. Party: Immigration Views*
# delimit ;

graph bar sample_r party_r if n<4, over(n, gap(*2)) 
	bar(1, color(black))
	bar(2, color(white) lcolor(black)) 
	blabel(bar, format(%6.1f) position(outside))
	graphregion(color(white)) 
	yline(0, lcolor(gray))
	yscale(range(0(10)50)) ylabel(0(10)50, nogrid) 
	ytitle("Percent" " ")
	legend(order(1 "Republican - Sample" 
	2 "Republican - National" ) rows(1))
	ylabel(, nogrid tlength(0))
	;
	# delimit cr

graph export "$draftout/A3_SampleCompare_Immigration_Republican.eps", replace

# delimit ;

graph bar sample_d party_d if n<4, over(n, gap(*2)) 
	bar(1, color(black))
	bar(2, color(white) lcolor(black)) 
	blabel(bar, format(%6.1f) position(outside))
	graphregion(color(white)) 
	yline(0, lcolor(gray))
	yscale(range(0(10)50)) ylabel(0(10)50, nogrid) 
	ytitle("Percent" " ")
	legend(order(1 "Democrat - Sample" 
	2 "Democrat - National" ) rows(1))
	ylabel(, nogrid tlength(0))
	;
	# delimit cr

graph export "$draftout/A3_SampleCompare_Immigration_Democrat.eps", replace



****************************************
****Bar Graphs of Comparison to Demographics****
****************************************


drop n
gen n=_n if _n<8

replace space=.

replace sample_r=.
replace sample_d=.
replace party_r=.
replace party_d=.

*Manually Enter National Party Info

gen male=1-female
*1.Gender*
*Source-Census
*https://www.census.gov/content/dam/Census/library/publications/2018/demo/P20-582.pdf
sum male if recruit==0
replace sample_r=r(mean)*100 if n==1
sum male if recruit==1
replace sample_d=r(mean)*100 if n==1
replace party_r=0.6*100 if n==1
replace party_d=0.46*100 if n==1

*2. White*
*Souce: https://www.pewresearch.org/2020/09/23/the-changing-racial-and-ethnic-composition-of-the-u-s-electorate/
sum white if recruit==0
replace sample_r=r(mean)*100 if n==2
sum white if recruit==1
replace sample_d=r(mean)*100 if n==2
replace party_r=0.86*100 if n==2
replace party_d=0.56*100 if n==2

*3. Black*
*Souce: https://www.pewresearch.org/2020/09/23/the-changing-racial-and-ethnic-composition-of-the-u-s-electorate/
sum black if recruit==0
replace sample_r=r(mean)*100 if n==3
sum black if recruit==1
replace sample_d=r(mean)*100 if n==3
replace party_r=0.03*100 if n==3
replace party_d=0.22*100 if n==3

*4. Hispanic*
*Souce: https://www.pewresearch.org/2020/09/23/the-changing-racial-and-ethnic-composition-of-the-u-s-electorate/
sum hispanic if recruit==0
replace sample_r=r(mean)*100 if n==4
sum hispanic if recruit==1
replace sample_d=r(mean)*100 if n==4
replace party_r=0.09*100 if n==4
replace party_d=0.16*100 if n==4

*5. College Degree*
*Source: https://www.census.gov/content/dam/Census/library/publications/2018/demo/P20-582.pdf
sum collegeorhigher if recruit==0
replace sample_r=r(mean)*100 if n==5
sum collegeorhigher if recruit==1
replace sample_d=r(mean)*100 if n==5
replace party_r=0.32*100 if n==5
replace party_d=0.42*100 if n==5

*6. Age<40*
*Souce: https://www.pewresearch.org/2020/09/23/the-changing-racial-and-ethnic-composition-of-the-u-s-electorate/
gen age_p55=agegroup>4
sum age_p55 if recruit==0
replace sample_r=r(mean)*100 if n==6
sum age_p55 if recruit==1
replace sample_d=r(mean)*100 if n==6
replace party_r=0.42*100 if n==6
replace party_d=0.37*100 if n==6


label define dem 1 `"Male "' ///
	2 `"White"' ///
	3 `"Black"' ///
	4 `"Hispanic"' ///
	5 `" "College" "Degree" "' ///
	6 `"Age>55"', replace 

label values n dem

*Sample vs. Party: Immigration Views*
# delimit ;

graph bar sample_r party_r if n<7, over(n, gap(*2)) 
	bar(1, color(black))
	bar(2, color(white) lcolor(black)) 
	blabel(bar, format(%6.1f) position(outside))
	graphregion(color(white)) 
	yline(0, lcolor(gray))
	yscale(range(0(10)100)) ylabel(0(10)100, nogrid) 
	ytitle("Percent" " ")
	legend(order(1 "Republican - Sample" 
	2 "Republican - National" ) rows(1))
	ylabel(, nogrid tlength(0))
	;
	# delimit cr

graph export "$draftout/A3_SampleCompare_Demog_Republican.eps", replace

# delimit ;

graph bar sample_d party_d if n<7, over(n, gap(*2)) 
	bar(1, color(black))
	bar(2, color(white) lcolor(black)) 
	blabel(bar, format(%6.1f) position(outside))
	graphregion(color(white)) 
	yline(0, lcolor(gray))
	yscale(range(0(10)70)) ylabel(0(10)70, nogrid) 
	ytitle("Percent" " ")
	legend(order(1 "Democrat - Sample" 
	2 "Democrat - National" ) rows(1))
	ylabel(, nogrid tlength(0))
	;
	# delimit cr

graph export "$draftout/A3_SampleCompare_Demog_Democrat.eps", replace




